# -*- utf-8 -*-
from typing import List


class Solution:
    def minimalSteps(self, maze: List[str]) -> int:
        count = 1
        arrays = []
        for i in maze:
            arrays.append(list(i))

        return count

    def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:
        ret = []
        last_index = 0
        for index in range(len(words)):
            item = words[last_index] + ' '
            flag = False
            for j in range(last_index + 1, len(words)):
                flag = True
                not_rep = False
                if j >= len(words):
                    break
                l = len(item) + len(words[j])
                if l <= maxWidth:
                    if l + 1 <= maxWidth:
                        item += words[j] + ' '
                    else:
                        item += words[j]
                else:
                    not_rep = True

                new_item = ''
                item = item.split(' ')
                if item[len(item) - 1] == '':
                    item = item[:-1]

                sub_item = item[:len(item) - 1]

                last_item = ' ' + item[len(item) - 1]

                kczkz = len(''.join(sub_item))

                if kczkz % 2 == 0:
                    pass
                else:
                    pass

                if not_rep:
                    temp = ' '.join(['' for _ in range(maxWidth - len(item))])
                    item += temp
                    break

                last_index = j + 1

            ret.append(item)
            if not flag:
                last_index += 1
            if last_index >= len(words):
                break

        return ret


if __name__ == '__main__':
    s = Solution()
    # s.minimalSteps(["S#O", "M..", "M.T"])
    ret = s.fullJustify(["Science", "is", "what", "we", "understand", "well", "enough", "to", "explain",
                         "to", "a", "computer.", "Art", "is", "everything", "else", "we", "do"], 20)
    print('\r\n'.join(ret))
